const express=require("express")
const app=express()


app.use((req,res,next)=>{
res.set("Access-Control-Allow-Origin",'*')
res.set("Access-Control-Allow-Headers", "*")

next()
})



app.get("/user",(req,res)=>{
    setTimeout(() => {
        const {
          userId
        } = req.query 
        if (userId !== '001') {
          return res.send({
            code: 10001,
            msg: "查询失败",
            data: null
          })
        }
        res.send({
          code: 10000,
          msg: "查询成功",
          data: {
            name: "李博",
            age: 18,
            sex: "男"
          }
        })
      }, 3000);
})

app.get("/user1",(req,res)=>{
    setTimeout(() => {
        const {
          userId
        } = req.query 
        if (userId !== '001') {
          return res.send({
            code: 10001,
            msg: "查询失败",
            data: null
          })
        }
        res.send({
          code: 10000,
          msg: "查询成功",
          data: {
            name: "李博",
            age: 18,
            sex: "男"
          }
        })
      }, 3000);
      // console.log(1);
})






app.listen(3000,()=>{
    console.log("启动成功");
})